package ac.leedsmet.devmanager.core;

import org.apache.log4j.Logger;

/**
 * This class is creating a new project story after it makes sure that there is a project attached on the specific story.
 *  After the story creation the auto increment method is giving a unique issue ID on the created story.
 * @author Samael
 * @version 1.0
 */
public class StoryManagerImpl implements StoryManager {

    protected static final Logger log = Logger.getLogger(IssueManagerImpl.class);
    private static long storyId = 100000L;
    Project project;

    public StoryManagerImpl(Project project) {
        this.project = project;
    }

    /**
     * Is creating an story after it makes sure that there is a project for that story and is giving
     * a unique id on that story as well
     * @param title the title of the new created story
     * @return the new created story
     */
    @Override
    public Story createStory(String title) {
        storyId++;
        Story story = new Story(storyId);
        story.setTitle(title);
        if(project.addStory(story)) {
            log.debug("Successfully added \"" + title + "\" story to \"" + project.getName() + "\" project");
        }
        return story;
    }
}
